package cn.xy.controller;

import cn.xy.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/test")
public class TestController {

    /**
     *  Controller获取数据,直接在url里面获取
     *  获取当个数据:
     *  例如这样:http://localhost:8080/test/t1?name=zhangsan
     *
     *  获取多个对象:注意,对象名必须都对应上,否则为null,获取不到
     *  http://localhost:8080/test/t2?id=1&username=zhangsan&password=123123
     *
     *  可以配合restFul风格使用
     */

    //获取参数
    @RequestMapping("/t1")
    public String test1(@RequestParam("username") String name){
        System.out.println(name);
        return null;
    }

    //获取对象
    @RequestMapping("/t2")
    public String test2(User user){
        System.out.println(user);
        return null;
    }

    //获取参数
    @RequestMapping("/t1/{id}/{username}/{password}")
    public String test3(@PathVariable String id,@PathVariable String username,@PathVariable String password){
        User user = new User(id,username,password);
        System.out.println(user);
        return null;
    }

}
